package ge.telasi.tasks;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * This class is a base for locale management. Currently it supports only
 * default locale. We need to extend it in the future.
 *
 * @author dimitri
 */
public abstract class LocaleManager {

    /**
     * Get plain message.
     */
    public String getMessage(String key) {
        try {
            return getResourceBundle().getString(key);
        } catch (MissingResourceException mre) {
            return key;
        }
    }

    /**
     * Get formatted message.
     */
    public String getMessage(String key, Object... others) {
        String rawMessage = getMessage(key);
        try {
            return MessageFormat.format(rawMessage, others);
        } catch (IllegalArgumentException ex) { // illegal arguments
            return rawMessage;
        }
    }

    /**
     * Get resource bundle.
     */
    protected abstract ResourceBundle getResourceBundle();

}
